<template>
  <drawRightsTemp
    :equityGroups="neddBuyRightPackage"
    :btnText="$t('guide.buy')"
    @btnClick="openBuy"
    @wndClose="onClose">
    <div slot="important2">
      {{$t('guide.somefunc')}}{{ neddBuyRightPackage | importantPackageName(true) }}{{$t('guide.vip')}}
    </div>
  </drawRightsTemp>
</template>
<script>
import mixin from './mixins'
import { isPassVersion } from '@/utils/judge'
import { pkgByCid } from '@/utils/costum'
export default {
  mixins: [mixin],
  data () {
    return {
      neddBuyRightPackage: []
    }
  },
  computed: {
    statIds () {
      return this.isNewInstall ? {
        show: 2575,
        go: 2576,
        close: 2577
      } : {
        show: 2635,
        go: 2636,
        close: 2637
      }
    }
  },
  mounted () {
    this.$xz('xz_substat_action', this.statIds.show)
    if (isPassVersion('3.1.0.5')) {
      this.$xzAsy('xz_is_vip_right_enough_pkgid').then(res => {
        if (res && res.NeedPkgID && res.NeedPkgID.length) {
          this.getList(res.NeedPkgID)
        }
      })
    } else {
      this.$xzAsy('xz_is_vip_right_enough').then(res => {
        if (res && res.NeedPkgID && res.NeedPkgID.length) {
          let pid = []
          for (const item of res.NeedPkgID) {
            pid = pid.concat(pkgByCid[item])
          }
          this.getList(pid)
        }
      })
    }
  },
  methods: {
    getList (pid) {
      this.getPackagesList({ pid }).then(res => {
        this.neddBuyRightPackage = res.data.list || []
      })
    },
    openBuy () {
      this.$xz('xz_substat_action', this.statIds.go)
      this.$xz('xz_call_vip_buy_wnd')
    },
    onClose () {
      this.$xz('xz_substat_action', this.statIds.close)
      this.$xz('xz_call_tips_wnd', 3)
    }
  }
}
</script>
